  <template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="loadCategory"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-button size="small" @click="toAddHandler">新增</el-button>
    </div>
    <!-- /按钮 -->
    <!-- 表格 -->
    <el-table size="small" :data="Category">
      <el-table-column label="id" prop="id"></el-table-column>
      <el-table-column label="名称" prop="name"></el-table-column>
      <el-table-column label="描述" prop="description"></el-table-column>
      <el-table-column label="no" prop="no"></el-table-column>
      <el-table-column label="parentId" prop="parentId"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="deleteHandler(scope.row)">删除</el-button>
          <el-button type="text" size="mini" @click="updateHandler(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
    <!-- 模态框 -->

    <!-- /模态框 -->
  </div>
</template>
<script>
import { del, get,post } from "@/utils/request";
export default {
  data() {
    return {
      // 参数，用于保存检索的参数
      param: {},
      // 组件模板中需要的数据
      Category: [],
    };
  },
  // 方法或者js的事件处理函数
  methods: {
    updateHandler(row){
       this.$router.push({
           path:"/category/create",
           query:row
       }) 

    },
    // 删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://121.196.106.124:8888/Category/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadCategory();
        });
      });
    },
    // 跳转
    toAddHandler() {
      this.$router.push("/Category/create");
    },
    // 查询后台中的应用信息
    loadCategory() {
      let url = "http://121.196.106.124:8888/Category/query";
      get(url, this.param).then((resp) => {
        this.Category = resp.data;
      });
    },
  },
  // 页面加载的时候会执行的方法
  created() {
    this.loadCategory();
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>
